package com.example.blackbox.Adapter;

import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import com.bumptech.glide.Glide;

import java.util.List;

public class BannerAdapter extends PagerAdapter {
    private List<String> mPics=null;
    @Override
    public int getCount() {
        if (mPics !=null){
            return mPics.size();
        }
        return 0;
    }

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView imageView=new ImageView(container.getContext());
//        imageView.setBackgroundColor(mColors.get(position));
        Glide.with(container).load(mPics.get(position)).into(imageView);        //设置完数据以后，就添加到容器李
        container.addView(imageView);
        return imageView;
    }

    @Override
    public boolean isViewFromObject(@NonNull View view, @NonNull Object object) {
        return view==object;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        container.removeView((View) object);
    }

    public void setData(List<String> sColos) {
        this.mPics=sColos;
    }
}
